We begin by loading our prepared AAVE transaction data into a dataframe. The dataset has over 400,000 rows, and 27 columns.
We are directly loading the dataframe from an Rds archive instead of a CSV file to conserve space.
#load Rds (binary version of csv file) into dataframe
# Assumes this notebook is in: ~/IDEA-Blockchain/DefiResearch/StudentNotebooks/Assignment02
df<-read_rds('../../Data/transactions.Rds')
# Let's take a quick look at the first few observation
head(df)
Now look at the summaries to see the types, values, and missingness (NA’s) of the data.
summary(df)
## amount borrowRate borrowRateMode onBehalfOf
## Min. : 0 Min. : 0.0 :386542 Min. :2.578e+33
## 1st Qu.: 24 1st Qu.: 3.3 Stable : 18408 1st Qu.:4.174e+47
## Median : 1427 Median : 3.9 Variable: 76569 Median :7.522e+47
## Mean : 191103 Mean : 9.5 Mean :7.592e+47
## 3rd Qu.: 24382 3rd Qu.: 10.8 3rd Qu.:1.168e+48
## Max. :600000000 Max. :10002.0 Max. :1.461e+48
## NA's :7289 NA's :386542 NA's :7289
## pool reserve timestamp user
## Min. :9.862e+47 USDC :105937 Min. :1.607e+09 Min. :2.578e+33
## 1st Qu.:1.035e+48 WETH :105279 1st Qu.:1.615e+09 1st Qu.:4.199e+47
## Median :1.035e+48 USDT : 58266 Median :1.621e+09 Median :8.697e+47
## Mean :1.034e+48 DAI : 55211 Mean :1.620e+09 Mean :8.082e+47
## 3rd Qu.:1.035e+48 LINK : 26404 3rd Qu.:1.624e+09 3rd Qu.:1.173e+48
## Max. :1.035e+48 WBTC : 26344 Max. :1.629e+09 Max. :1.461e+48
## (Other):104078
## type reservePriceETH reservePriceUSD
## borrow : 94977 Min. :1.000e+00 Min. :0.000e+00
## deposit :192006 1st Qu.:2.865e+14 1st Qu.:1.000e+00
## liquidation: 6289 Median :4.652e+14 Median :1.000e+00
## redeem :126705 Mean :3.458e+23 Mean :6.774e+08
## repay : 60542 3rd Qu.:9.411e+14 3rd Qu.:1.000e+00
## swap : 1000 Max. :1.647e+28 Max. :4.252e+13
## NA's :7289 NA's :7289
## amountUSD collateralAmount collateralReserve principalAmount
## Min. : 0 Min. : 0 :475230 Min. : 0
## 1st Qu.: 70 1st Qu.: 1 WETH : 2665 1st Qu.: 962
## Median : 5836 Median : 14 LINK : 1312 Median : 4362
## Mean : 245851 Mean : 5451 WBTC : 686 Mean : 66005
## 3rd Qu.: 49871 3rd Qu.: 250 AAVE : 333 3rd Qu.: 21533
## Max. :754379487 Max. :4638724 UNI : 230 Max. :4475668
## NA's :7289 NA's :475230 (Other): 1063 NA's :475230
## principalReserve reservePriceETHPrincipal reservePriceUSDPrincipal
## :475230 Min. :1.000e+00 Min. : 0.0
## USDC : 2142 1st Qu.:4.062e+14 1st Qu.: 1.0
## USDT : 1549 Median :4.682e+14 Median : 1.0
## DAI : 1459 Mean :1.556e+17 Mean : 295.6
## GUSD : 242 3rd Qu.:5.363e+14 3rd Qu.: 1.0
## TUSD : 175 Max. :4.203e+19 Max. :83819.1
## (Other): 722 NA's :475230 NA's :475230
## reservePriceETHCollateral reservePriceUSDCollateral amountUSDPincipal
## Min. :1.000e+00 Min. :0.000e+00 Min. : 0
## 1st Qu.:1.000e+00 1st Qu.:0.000e+00 1st Qu.: 1022
## Median :5.110e+14 Median :1.000e+00 Median : 4481
## Mean :2.177e+21 Mean :4.543e+06 Mean : 67361
## 3rd Qu.:1.110e+16 3rd Qu.:2.600e+01 3rd Qu.: 22066
## Max. :9.116e+23 Max. :2.509e+09 Max. :4571839
## NA's :475230 NA's :475230 NA's :475230
## amountUSDCollateral borrowRateModeFrom borrowRateModeTo stableBorrowRate
## Min. : 0 :480519 :480519 Min. : 0.0
## 1st Qu.: 0 Stable : 471 Stable : 529 1st Qu.: 9.0
## Median : 476 Variable: 529 Variable: 471 Median : 10.9
## Mean : 37060 Mean : 11.7
## 3rd Qu.: 7457 3rd Qu.: 12.0
## Max. :5029023 Max. :154.7
## NA's :475230 NA's :480519
## variableBorrowRate
## Min. : 0.0
## 1st Qu.: 3.8
## Median : 3.9
## Mean : 5.7
## 3rd Qu.: 5.1
## Max. :148.7
## NA's :480519
First we’ll do some preliminary analysis before we ask detailed questions.
Let’s examine the different types of transactions present in the data. We’ll make a simple bar plot to visualize the number of each transaction types. “Deposit” is the most common type of transaction, whereas “swaps” are the most rare.
#set color palette
colors = brewer.pal(6,"Set2")
#create barplot
barplot(table(df$type), main='Transaction Type Counts', xlab='Type',ylab='Count',col=colors)
There are more “deposits” than “borrows,” because users often need to overcollateralize for loans.
Now we’ll examine the amount of US dollars being used in the different types of transactions. We create box plots for the four types of transactions that have the “amount” feature associated with them, and we visualize the distribution of that column for the different transactions.
We can see that most transactions are completed with very little money.
#create boxplot
boxplot(amountUSD~type,data=df,outline=FALSE,col=colors,
main="Transaction Amounts",xlab="Type",ylab="Amount (USD)")
We do find some very large amounts, so it’s helpful to look at this on a log scale.
boxplot(log(amountUSD)~type,data=df,outline=FALSE,col=colors,
main="Log Transaction Amounts",xlab="Type",ylab="Log Amount (USD)")
Observation: There are many borrows and repays with high transactions amounts, but deposits and redeems have much lower transactions amounts.
There are 50 different “Reserve” coins used in transactions in AAVE. Let’s create a table of those reserve coins with at least 500 transactions and rank order them by their volume.
# Use deplyr to drop NA reserves, add the counts and then kep only the top 20
reservecoins <- df %>% drop_na(reserve) %>%
count(reserve) %>%
arrange(-n) %>%
head(20)
# Add the rank to help keep track of the reserve coins
reservecoins <- reservecoins %>%
mutate(rank=1:nrow(reservecoins),.before=reserve)
# List the results nicely with kable()
kable(reservecoins)
| rank | reserve | n |
|---|---|---|
| 1 | USDC | 105937 |
| 2 | WETH | 105279 |
| 3 | USDT | 58266 |
| 4 | DAI | 55211 |
| 5 | LINK | 26404 |
| 6 | WBTC | 26344 |
| 7 | AAVE | 12174 |
| 8 | CRV | 10593 |
| 9 | UNI | 7547 |
| 10 | XSUSHI | 7337 |
| 11 | SNX | 6938 |
| 12 | SUSD | 6542 |
| 13 | 6289 | |
| 14 | GUSD | 6009 |
| 15 | YFI | 5919 |
| 16 | BUSD | 4863 |
| 17 | TUSD | 3317 |
| 18 | BAL | 3152 |
| 19 | MKR | 3101 |
| 20 | REN | 2638 |
Let’s look at the number of transactions types for each currency.
TopcoinSummary <- df %>% filter(reserve %in% reservecoins$reserve) %>%
group_by(reserve) %>%
count(type) %>%
mutate(percent = n/sum(n)*100)
kable(TopcoinSummary)
| reserve | type | n | percent |
|---|---|---|---|
| liquidation | 6289 | 100.0000000 | |
| AAVE | borrow | 2 | 0.0164285 |
| AAVE | deposit | 7028 | 57.7295876 |
| AAVE | redeem | 5141 | 42.2293412 |
| AAVE | repay | 3 | 0.0246427 |
| BAL | borrow | 215 | 6.8210660 |
| BAL | deposit | 2171 | 68.8769036 |
| BAL | redeem | 612 | 19.4162437 |
| BAL | repay | 154 | 4.8857868 |
| BUSD | borrow | 1685 | 34.6493934 |
| BUSD | deposit | 1135 | 23.3395024 |
| BUSD | redeem | 836 | 17.1910343 |
| BUSD | repay | 1207 | 24.8200699 |
| CRV | borrow | 1054 | 9.9499670 |
| CRV | deposit | 5780 | 54.5643349 |
| CRV | redeem | 2607 | 24.6105919 |
| CRV | repay | 1152 | 10.8751062 |
| DAI | borrow | 14133 | 25.5981598 |
| DAI | deposit | 18552 | 33.6019996 |
| DAI | redeem | 13381 | 24.2361124 |
| DAI | repay | 8895 | 16.1109199 |
| DAI | swap | 250 | 0.4528083 |
| GUSD | borrow | 2282 | 37.9763688 |
| GUSD | deposit | 1493 | 24.8460642 |
| GUSD | redeem | 967 | 16.0925279 |
| GUSD | repay | 1267 | 21.0850391 |
| LINK | borrow | 1321 | 5.0030298 |
| LINK | deposit | 15270 | 57.8321466 |
| LINK | redeem | 8713 | 32.9987881 |
| LINK | repay | 1097 | 4.1546735 |
| LINK | swap | 3 | 0.0113619 |
| MKR | borrow | 188 | 6.0625605 |
| MKR | deposit | 1766 | 56.9493712 |
| MKR | redeem | 986 | 31.7961948 |
| MKR | repay | 159 | 5.1273783 |
| MKR | swap | 2 | 0.0644953 |
| REN | borrow | 196 | 7.4298711 |
| REN | deposit | 1417 | 53.7149356 |
| REN | redeem | 840 | 31.8423048 |
| REN | repay | 183 | 6.9370735 |
| REN | swap | 2 | 0.0758150 |
| SNX | borrow | 433 | 6.2409916 |
| SNX | deposit | 4002 | 57.6823292 |
| SNX | redeem | 2052 | 29.5762468 |
| SNX | repay | 451 | 6.5004324 |
| SUSD | borrow | 1277 | 19.5200245 |
| SUSD | deposit | 2403 | 36.7318863 |
| SUSD | redeem | 1781 | 27.2240905 |
| SUSD | repay | 1081 | 16.5239988 |
| TUSD | borrow | 991 | 29.8763943 |
| TUSD | deposit | 853 | 25.7160084 |
| TUSD | redeem | 661 | 19.9276455 |
| TUSD | repay | 796 | 23.9975882 |
| TUSD | swap | 16 | 0.4823636 |
| UNI | borrow | 567 | 7.5129190 |
| UNI | deposit | 3912 | 51.8351663 |
| UNI | redeem | 2540 | 33.6557573 |
| UNI | repay | 527 | 6.9829071 |
| UNI | swap | 1 | 0.0132503 |
| USDC | borrow | 35469 | 33.4812200 |
| USDC | deposit | 27586 | 26.0400049 |
| USDC | redeem | 22131 | 20.8907181 |
| USDC | repay | 20326 | 19.1868752 |
| USDC | swap | 425 | 0.4011818 |
| USDT | borrow | 22332 | 38.3276697 |
| USDT | deposit | 12593 | 21.6129475 |
| USDT | redeem | 10349 | 17.7616449 |
| USDT | repay | 12719 | 21.8291971 |
| USDT | swap | 273 | 0.4685408 |
| WBTC | borrow | 2082 | 7.9031278 |
| WBTC | deposit | 13994 | 53.1202551 |
| WBTC | redeem | 8442 | 32.0452475 |
| WBTC | repay | 1816 | 6.8934103 |
| WBTC | swap | 10 | 0.0379593 |
| WETH | borrow | 7234 | 6.8712659 |
| WETH | deposit | 56373 | 53.5462913 |
| WETH | redeem | 35505 | 33.7246744 |
| WETH | repay | 6155 | 5.8463701 |
| WETH | swap | 12 | 0.0113983 |
| XSUSHI | borrow | 242 | 3.2983508 |
| XSUSHI | deposit | 4382 | 59.7246831 |
| XSUSHI | redeem | 2454 | 33.4469129 |
| XSUSHI | repay | 259 | 3.5300532 |
| YFI | borrow | 403 | 6.8085825 |
| YFI | deposit | 2976 | 50.2787633 |
| YFI | redeem | 2146 | 36.2561243 |
| YFI | repay | 394 | 6.6565298 |
Finally, we will examine the transaction history of different users. To do this, we will select 3 random users from the data who have completed between 100 and 300 transactions. Then, we create swarmplots displaying the different types of transactions those users made over time.
#set seed
set.seed(1)
# Select three random users that have between 100 and 300 transactions
users<-vector(length=3)
count<-0
while(count<=3){
success<-FALSE
while(!success){
#get random user
ruser<-sample(df$user,1)
#check for valid number of transactions
length<-nrow(filter(df,user==ruser))
if (length>100 && length<300){
users[count]=ruser
success<-TRUE
count<-count+1
}
}
}
df.rusers<-filter(df, user %in%users)
# Create a "swarmplot"
ggplot(df.rusers,aes(user, timestamp,color=type)) +
geom_beeswarm(cex=1)+
coord_flip()+
ggtitle("User Transaction History")
Observation: Users have very different transactions patterns, which we will try to better understand.
For readability in the future let’s add a column to the data with the datetimes of each transaction.
df <- df %>%
mutate(datetime = as_datetime(timestamp))
stableBorrows <- df %>%
filter(borrowRateMode == 'Stable') %>%
select(amount, borrowRate, reserve, reservePriceETH, reservePriceUSD, amountUSD) %>%
group_by(reserve) %>%
summarise(meanBorrowRate = mean(borrowRate), meanAmountUSD = mean(amountUSD)) %>%
arrange(-meanAmountUSD)
kable(stableBorrows)
| reserve | meanBorrowRate | meanAmountUSD |
|---|---|---|
| WBTC | 4.2390575 | 5.560887e+05 |
| LINK | 4.1593373 | 3.869544e+05 |
| MKR | 4.2695021 | 1.532603e+05 |
| TUSD | 14.7699809 | 7.857025e+04 |
| USDT | 13.2979463 | 7.522208e+04 |
| USDC | 12.2011867 | 7.125035e+04 |
| DAI | 14.3987054 | 6.952764e+04 |
| MANA | 4.4445942 | 6.839591e+04 |
| BAT | 5.6596412 | 5.655844e+04 |
| REN | 1.6789213 | 4.323582e+04 |
| KNC | 10.2808363 | 2.785920e+04 |
| ZRX | 4.4377931 | 1.898568e+04 |
| ENJ | 0.6129458 | 1.750630e+04 |
| UNI | 5.2818956 | 4.063297e-01 |
| WETH | 4.5540876 | 0.000000e+00 |
ggplot(stableBorrows, aes(meanBorrowRate, meanAmountUSD)) + geom_point() + ggtitle("Stable Rate Borrows by Coin") + xlab("Average Borrow Rate (% APY)") + ylab("Average Amount Borrowed (USD)")
variableBorrows <- df %>%
filter(borrowRateMode == 'Variable') %>%
select(amount, borrowRate, reserve, reservePriceETH, reservePriceUSD, amountUSD, variableBorrowRate) %>%
group_by(reserve) %>%
summarise(meanBorrowRate = mean(borrowRate), meanAmountUSD = mean(amountUSD)) %>%
arrange(-meanAmountUSD)
kable(variableBorrows)
| reserve | meanBorrowRate | meanAmountUSD |
|---|---|---|
| PAX | 1.4189667 | 759194.21381 |
| YFI | 25.0423153 | 579352.73415 |
| USDC | 7.3136164 | 465590.74771 |
| WBTC | 0.8969733 | 456755.49539 |
| XSUSHI | 0.4389817 | 430386.33101 |
| DAI | 9.2355330 | 354431.30876 |
| SNX | 16.6542886 | 309288.28960 |
| USDT | 7.5154919 | 306093.68839 |
| SUSD | 11.4928812 | 221874.51600 |
| UNI | 1.4402381 | 208870.57160 |
| TUSD | 14.5124541 | 169636.71608 |
| AmmWBTC | 7.6796791 | 153694.88693 |
| ENJ | 6.3437707 | 146525.18717 |
| LINK | 0.4668825 | 135880.07066 |
| REN | 4.3690875 | 135343.87096 |
| AmmUSDT | 11.6201854 | 124174.97422 |
| AmmUSDC | 11.7120704 | 117880.03931 |
| RAI | 21.0781242 | 110328.02862 |
| RENFIL | 9.5067321 | 104352.92464 |
| CRV | 49.9247441 | 104106.11557 |
| MKR | 6.0872225 | 99000.98792 |
| BUSD | 9.7180112 | 86287.81560 |
| BAL | 14.2020852 | 74815.48914 |
| GUSD | 7.0424511 | 54016.82953 |
| KNC | 21.4718490 | 48757.60156 |
| MANA | 6.9657417 | 48672.45181 |
| BAT | 6.1808241 | 27723.46389 |
| AMPL | 175.8169717 | 21739.83824 |
| AmmDAI | 8.6259297 | 21009.53690 |
| ZRX | 3.5022303 | 10874.09762 |
| AAVE | 0.0000000 | 2.17796 |
| AmmWETH | 9.8078071 | 0.00000 |
| WETH | 1.1912801 | 0.00000 |
ggplot(variableBorrows, aes(meanBorrowRate, meanAmountUSD)) + geom_point() + ggtitle("Variable Rate Borrows by Coin") + xlab("Average Borrow Rate (% APY)") + ylab("Average Amount Borrowed (USD)")
allCoins <- df %>%
group_by(reserve) %>%
count(reserve) %>%
arrange(-n)
kable(allCoins)
| reserve | n |
|---|---|
| USDC | 105937 |
| WETH | 105279 |
| USDT | 58266 |
| DAI | 55211 |
| LINK | 26404 |
| WBTC | 26344 |
| AAVE | 12174 |
| CRV | 10593 |
| UNI | 7547 |
| XSUSHI | 7337 |
| SNX | 6938 |
| SUSD | 6542 |
| 6289 | |
| GUSD | 6009 |
| YFI | 5919 |
| BUSD | 4863 |
| TUSD | 3317 |
| BAL | 3152 |
| MKR | 3101 |
| REN | 2638 |
| ENJ | 2457 |
| MANA | 1993 |
| AmmWETH | 1778 |
| RAI | 1532 |
| AMPL | 1497 |
| AmmUSDC | 1405 |
| BAT | 1377 |
| KNC | 1349 |
| AmmDAI | 1266 |
| ZRX | 905 |
| AmmUSDT | 825 |
| AmmWBTC | 344 |
| AmmBptBALWETH | 244 |
| AmmBptWBTCWETH | 159 |
| AmmUniUSDCWETH | 136 |
| RENFIL | 90 |
| AmmUniUNIWETH | 68 |
| AmmUniWBTCWETH | 57 |
| AmmUniDAIWETH | 52 |
| AmmUniLINKWETH | 43 |
| AmmUniAAVEWETH | 19 |
| AmmUniCRVWETH | 11 |
| PAX | 11 |
| AmmUniWBTCUSDC | 10 |
| AmmUniSNXWETH | 7 |
| AmmUniRENWETH | 6 |
| AmmUniYFIWETH | 6 |
| AmmUniMKRWETH | 5 |
| AmmUniBATWETH | 4 |
| AmmUniDAIUSDC | 3 |
stableCoins <- df %>%
filter(reserve == 'USDT' | reserve == 'USDC' | reserve == 'GUSD' | reserve == 'DAI' | reserve == 'WBTC' | reserve == 'SUSD' | reserve == 'TUSD') %>%
group_by(reserve) %>%
count(reserve) %>%
arrange(-n)
kable(stableCoins)
| reserve | n |
|---|---|
| USDC | 105937 |
| USDT | 58266 |
| DAI | 55211 |
| WBTC | 26344 |
| SUSD | 6542 |
| GUSD | 6009 |
| TUSD | 3317 |
stableCoinTransactions <- df %>%
filter(reserve %in% stableCoins$reserve) %>%
group_by(reserve) %>%
count(type) %>%
mutate(percent = n/sum(n)*100)
kable(stableCoinTransactions)
| reserve | type | n | percent |
|---|---|---|---|
| DAI | borrow | 14133 | 25.5981598 |
| DAI | deposit | 18552 | 33.6019996 |
| DAI | redeem | 13381 | 24.2361124 |
| DAI | repay | 8895 | 16.1109199 |
| DAI | swap | 250 | 0.4528083 |
| GUSD | borrow | 2282 | 37.9763688 |
| GUSD | deposit | 1493 | 24.8460642 |
| GUSD | redeem | 967 | 16.0925279 |
| GUSD | repay | 1267 | 21.0850391 |
| SUSD | borrow | 1277 | 19.5200245 |
| SUSD | deposit | 2403 | 36.7318863 |
| SUSD | redeem | 1781 | 27.2240905 |
| SUSD | repay | 1081 | 16.5239988 |
| TUSD | borrow | 991 | 29.8763943 |
| TUSD | deposit | 853 | 25.7160084 |
| TUSD | redeem | 661 | 19.9276455 |
| TUSD | repay | 796 | 23.9975882 |
| TUSD | swap | 16 | 0.4823636 |
| USDC | borrow | 35469 | 33.4812200 |
| USDC | deposit | 27586 | 26.0400049 |
| USDC | redeem | 22131 | 20.8907181 |
| USDC | repay | 20326 | 19.1868752 |
| USDC | swap | 425 | 0.4011818 |
| USDT | borrow | 22332 | 38.3276697 |
| USDT | deposit | 12593 | 21.6129475 |
| USDT | redeem | 10349 | 17.7616449 |
| USDT | repay | 12719 | 21.8291971 |
| USDT | swap | 273 | 0.4685408 |
| WBTC | borrow | 2082 | 7.9031278 |
| WBTC | deposit | 13994 | 53.1202551 |
| WBTC | redeem | 8442 | 32.0452475 |
| WBTC | repay | 1816 | 6.8934103 |
| WBTC | swap | 10 | 0.0379593 |
ammCoins <- df %>%
filter(grepl('Amm', reserve))%>%
group_by(reserve) %>%
count(reserve) %>%
arrange(-n)
ammCoinTransactions <- df %>%
filter(reserve %in% ammCoins$reserve) %>%
group_by(reserve) %>%
count(type) %>%
mutate(percent = n/sum(n)*100)
kable(ammCoinTransactions)
| reserve | type | n | percent |
|---|---|---|---|
| AmmBptBALWETH | deposit | 171 | 70.081967 |
| AmmBptBALWETH | redeem | 73 | 29.918033 |
| AmmBptWBTCWETH | deposit | 97 | 61.006289 |
| AmmBptWBTCWETH | redeem | 62 | 38.993711 |
| AmmDAI | borrow | 529 | 41.785150 |
| AmmDAI | deposit | 289 | 22.827804 |
| AmmDAI | redeem | 209 | 16.508689 |
| AmmDAI | repay | 239 | 18.878357 |
| AmmUniAAVEWETH | deposit | 11 | 57.894737 |
| AmmUniAAVEWETH | redeem | 8 | 42.105263 |
| AmmUniBATWETH | deposit | 3 | 75.000000 |
| AmmUniBATWETH | redeem | 1 | 25.000000 |
| AmmUniCRVWETH | deposit | 8 | 72.727273 |
| AmmUniCRVWETH | redeem | 3 | 27.272727 |
| AmmUniDAIUSDC | deposit | 2 | 66.666667 |
| AmmUniDAIUSDC | redeem | 1 | 33.333333 |
| AmmUniDAIWETH | deposit | 32 | 61.538461 |
| AmmUniDAIWETH | redeem | 20 | 38.461539 |
| AmmUniLINKWETH | deposit | 30 | 69.767442 |
| AmmUniLINKWETH | redeem | 13 | 30.232558 |
| AmmUniMKRWETH | deposit | 4 | 80.000000 |
| AmmUniMKRWETH | redeem | 1 | 20.000000 |
| AmmUniRENWETH | deposit | 3 | 50.000000 |
| AmmUniRENWETH | redeem | 3 | 50.000000 |
| AmmUniSNXWETH | deposit | 3 | 42.857143 |
| AmmUniSNXWETH | redeem | 4 | 57.142857 |
| AmmUniUNIWETH | deposit | 42 | 61.764706 |
| AmmUniUNIWETH | redeem | 26 | 38.235294 |
| AmmUniUSDCWETH | deposit | 82 | 60.294118 |
| AmmUniUSDCWETH | redeem | 54 | 39.705882 |
| AmmUniWBTCUSDC | deposit | 6 | 60.000000 |
| AmmUniWBTCUSDC | redeem | 4 | 40.000000 |
| AmmUniWBTCWETH | deposit | 37 | 64.912281 |
| AmmUniWBTCWETH | redeem | 20 | 35.087719 |
| AmmUniYFIWETH | deposit | 5 | 83.333333 |
| AmmUniYFIWETH | redeem | 1 | 16.666667 |
| AmmUSDC | borrow | 283 | 20.142349 |
| AmmUSDC | deposit | 537 | 38.220641 |
| AmmUSDC | redeem | 369 | 26.263345 |
| AmmUSDC | repay | 216 | 15.373665 |
| AmmUSDT | borrow | 180 | 21.818182 |
| AmmUSDT | deposit | 297 | 36.000000 |
| AmmUSDT | redeem | 209 | 25.333333 |
| AmmUSDT | repay | 139 | 16.848485 |
| AmmWBTC | borrow | 48 | 13.953488 |
| AmmWBTC | deposit | 163 | 47.383721 |
| AmmWBTC | redeem | 99 | 28.779070 |
| AmmWBTC | repay | 34 | 9.883721 |
| AmmWETH | borrow | 180 | 10.123734 |
| AmmWETH | deposit | 1014 | 57.030371 |
| AmmWETH | redeem | 473 | 26.602925 |
| AmmWETH | repay | 111 | 6.242970 |
unstableCoins <- df%>%
filter(! reserve %in% stableCoins$reserve & ! reserve %in% ammCoins$reserve) %>%
group_by(reserve) %>%
count(reserve) %>%
arrange(-n)
unstableCoinTransactions <- df %>%
filter(reserve %in% unstableCoins$reserve) %>%
group_by(reserve) %>%
count(type) %>%
mutate(percent = n/sum(n)*100)
kable(unstableCoinTransactions)
| reserve | type | n | percent |
|---|---|---|---|
| liquidation | 6289 | 100.0000000 | |
| AAVE | borrow | 2 | 0.0164285 |
| AAVE | deposit | 7028 | 57.7295876 |
| AAVE | redeem | 5141 | 42.2293412 |
| AAVE | repay | 3 | 0.0246427 |
| AMPL | borrow | 438 | 29.2585170 |
| AMPL | deposit | 601 | 40.1469606 |
| AMPL | redeem | 301 | 20.1068804 |
| AMPL | repay | 157 | 10.4876420 |
| BAL | borrow | 215 | 6.8210660 |
| BAL | deposit | 2171 | 68.8769036 |
| BAL | redeem | 612 | 19.4162437 |
| BAL | repay | 154 | 4.8857868 |
| BAT | borrow | 158 | 11.4742193 |
| BAT | deposit | 750 | 54.4662309 |
| BAT | redeem | 335 | 24.3282498 |
| BAT | repay | 132 | 9.5860566 |
| BAT | swap | 2 | 0.1452433 |
| BUSD | borrow | 1685 | 34.6493934 |
| BUSD | deposit | 1135 | 23.3395024 |
| BUSD | redeem | 836 | 17.1910343 |
| BUSD | repay | 1207 | 24.8200699 |
| CRV | borrow | 1054 | 9.9499670 |
| CRV | deposit | 5780 | 54.5643349 |
| CRV | redeem | 2607 | 24.6105919 |
| CRV | repay | 1152 | 10.8751062 |
| ENJ | borrow | 234 | 9.5238095 |
| ENJ | deposit | 1302 | 52.9914530 |
| ENJ | redeem | 681 | 27.7167277 |
| ENJ | repay | 239 | 9.7273097 |
| ENJ | swap | 1 | 0.0407000 |
| KNC | borrow | 136 | 10.0815419 |
| KNC | deposit | 643 | 47.6649370 |
| KNC | redeem | 411 | 30.4670126 |
| KNC | repay | 157 | 11.6382506 |
| KNC | swap | 2 | 0.1482580 |
| LINK | borrow | 1321 | 5.0030298 |
| LINK | deposit | 15270 | 57.8321466 |
| LINK | redeem | 8713 | 32.9987881 |
| LINK | repay | 1097 | 4.1546735 |
| LINK | swap | 3 | 0.0113619 |
| MANA | borrow | 220 | 11.0386352 |
| MANA | deposit | 1018 | 51.0787757 |
| MANA | redeem | 563 | 28.2488710 |
| MANA | repay | 192 | 9.6337180 |
| MKR | borrow | 188 | 6.0625605 |
| MKR | deposit | 1766 | 56.9493712 |
| MKR | redeem | 986 | 31.7961948 |
| MKR | repay | 159 | 5.1273783 |
| MKR | swap | 2 | 0.0644953 |
| PAX | borrow | 8 | 72.7272727 |
| PAX | deposit | 2 | 18.1818182 |
| PAX | redeem | 1 | 9.0909091 |
| RAI | borrow | 352 | 22.9765013 |
| RAI | deposit | 644 | 42.0365535 |
| RAI | redeem | 326 | 21.2793734 |
| RAI | repay | 210 | 13.7075718 |
| REN | borrow | 196 | 7.4298711 |
| REN | deposit | 1417 | 53.7149356 |
| REN | redeem | 840 | 31.8423048 |
| REN | repay | 183 | 6.9370735 |
| REN | swap | 2 | 0.0758150 |
| RENFIL | borrow | 29 | 32.2222222 |
| RENFIL | deposit | 28 | 31.1111111 |
| RENFIL | redeem | 11 | 12.2222222 |
| RENFIL | repay | 22 | 24.4444444 |
| SNX | borrow | 433 | 6.2409916 |
| SNX | deposit | 4002 | 57.6823292 |
| SNX | redeem | 2052 | 29.5762468 |
| SNX | repay | 451 | 6.5004324 |
| UNI | borrow | 567 | 7.5129190 |
| UNI | deposit | 3912 | 51.8351663 |
| UNI | redeem | 2540 | 33.6557573 |
| UNI | repay | 527 | 6.9829071 |
| UNI | swap | 1 | 0.0132503 |
| WETH | borrow | 7234 | 6.8712659 |
| WETH | deposit | 56373 | 53.5462913 |
| WETH | redeem | 35505 | 33.7246744 |
| WETH | repay | 6155 | 5.8463701 |
| WETH | swap | 12 | 0.0113983 |
| XSUSHI | borrow | 242 | 3.2983508 |
| XSUSHI | deposit | 4382 | 59.7246831 |
| XSUSHI | redeem | 2454 | 33.4469129 |
| XSUSHI | repay | 259 | 3.5300532 |
| YFI | borrow | 403 | 6.8085825 |
| YFI | deposit | 2976 | 50.2787633 |
| YFI | redeem | 2146 | 36.2561243 |
| YFI | repay | 394 | 6.6565298 |
| ZRX | borrow | 76 | 8.3977901 |
| ZRX | deposit | 496 | 54.8066298 |
| ZRX | redeem | 279 | 30.8287293 |
| ZRX | repay | 53 | 5.8563536 |
| ZRX | swap | 1 | 0.1104972 |
borrowRateSwaps <- df %>%
filter(type == 'swap') %>%
select(borrowRateModeFrom, borrowRateModeTo, reserve, variableBorrowRate, stableBorrowRate, timestamp, user, onBehalfOf) %>%
group_by(borrowRateModeFrom) %>%
mutate(vsRatio = variableBorrowRate/stableBorrowRate)
variableSwaps <- borrowRateSwaps %>%
filter(borrowRateModeFrom == 'Variable')
varToStable <- ggplot(variableSwaps, aes(variableBorrowRate, stableBorrowRate)) +
geom_point(aes(color = variableSwaps$reserve)) +
ggtitle("Swaps from Variable to Stable Borrows") +
geom_abline(slope = 1, intercept = 0)
ggplotly(varToStable)
stableSwaps <- borrowRateSwaps %>%
filter(borrowRateModeFrom == 'Stable')
stableToVar <- ggplot(stableSwaps, aes(stableBorrowRate, variableBorrowRate)) +
geom_point(aes(color = stableSwaps$reserve)) +
ggtitle("Swaps from Stable to Variable Borrows") +
geom_abline(slope = 1, intercept = 0)
ggplotly(stableToVar)
brsUSDT <- borrowRateSwaps %>%
filter(reserve == 'USDT')%>%
group_by(user) %>%
mutate(vsRatio = variableBorrowRate/stableBorrowRate)
swapRatioOverTime <- ggplot(borrowRateSwaps, aes(as_datetime(timestamp), vsRatio)) +
geom_point(aes(color = borrowRateModeFrom)) +
ggtitle("Variable/Stable Ratios Over Time (USDT)")
ggplotly(swapRatioOverTime)
borrowsUSDT <- df %>%
filter(type=='borrow', reserve == 'USDT')
stableBorrowsUSDT <- borrowsUSDT %>%
filter(borrowRateMode == 'Stable')
stableRatesOverTime <- ggplot(stableBorrowsUSDT, aes(as_datetime(timestamp), borrowRate)) +
geom_point(aes(color = reserve)) +
ggtitle("Stable Borrow Rates Over Time (USDT)")
ggplotly(stableRatesOverTime)
Let’s take a look at the stable borrow rates of USDT as they vary from week to week:
variableBorrowsUSDT <- borrowsUSDT %>%
filter(borrowRateMode == 'Variable')
varRatesOverTime <- ggplot(variableBorrowsUSDT, aes(as_datetime(timestamp), borrowRate)) +
geom_point(aes(color = reserve)) +
ggtitle("Variable Borrow Rates Over Time (USDT)")
ggplotly(varRatesOverTime)